import requests
import json

host = 'localhost:9000'  # scmp.csair.com
# host = '10.79.13.103:80'

# url = f"http://{host}/scmp-manage/sys/user/login?username=_SSO_T_23072&password=1A7384C1588A3471A72268DA3B117090&code=test"  # 替换为你要访问的HTTPS API地址

url = f"http://{host}/scmp-manage/sys/user/login?username=admin&password=F42C6DC42C7528E552C023D418CD5192&code=test"

# data = {
#     "username": "_SSO_T_23072",
#     "password": "1A7384C1588A3471A72268DA3B117090",
#     "code": "test"
# }  # 替换为你要发送的数据

def login():
    # 发送POST请求
    response = requests.post(url)
    # 检查请求是否成功
    if response.status_code == 200:
        # 如果成功，打印响应内容
        print(response.text)
        respText = json.loads(response.text)
        token = 'Bearer ' + respText['data']['token']
        print(token)
        return {
            'Authorization': token,
            'User-Agent': 'Apifox/01基础.0.0 (https://www.apifox.cn)',
            'Content-Type': 'application/json',
            'Accept': '*/*',
            'Host': '10.79.13.103:80',
            'Connection': 'keep-alive'
        }
    else:
        # 如果失败，打印错误信息
        print(f"请求失败，状态码：{response.status_code}")


def getData():
    url_getTotalQuantity = f'http://{host}/scmp-manage/sys/index/getTotalQuantity'
    # url_getTotalQuantity = 'http://10.79.13.103:80/scmp-manage/sys/index/getTotalQuantity'
    headers = login()
    payload = json.dumps({
        "startTime": "2024-04-12",
        "endTime": "2024-04-18"
    })

    response = requests.post(url_getTotalQuantity, data=payload, headers=headers)
    respText = json.loads(response.text)
    print(respText['data'])


getData()
